<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="user-scalable=no,width=device-width, initial-scale=1" id="viewport" name="viewport" initial-scale="1">
<script language="javascript" type="text/javascript" src="../js/js/baseJs.js"></script>

</head>
<body>

<div class="wap-register" id="wapRegister" style="display: none;">
  <div class="wap-header">修改密码
    <a class="back" onClick="javascript:window.history.back();return false;"></a>
  </div>
  <div class="register-bd"> 
    <div class="ln-account"><input oninput="if(value.length>11)value=value.slice(0,11)" placeholder="手机账号" v-model="mobileNumber"></div>
    <div class="ln-Ver-code">
      <input  placeholder="验证码" v-model="verification">
      <div class="send-code" v-on:click="sendSms" v-bind:disabled="isSendingSms || (countDownNumber > 0)">
        <span v-if="countDownNumber==0">获取验证码</span>
        <span v-if="countDownNumber>0">({{countDownNumber}}S)</span>
      </div>
    </div>
    <div class="ln-Ver-key"><input  placeholder="新密码" type="password"  onfocus="this.removeAttribute('readonly');" v-model="password"></div>
    <div class="comfirm-button" @click="registerAccount">确定修改</div>
    <a class="go-login" href="./login.mobile.html">去登陆</a>
  </div>
</div>

<script type="text/javascript">
  require(["../js/js/base_config"], function (baseContent) {
    // console.log(baseContent.cdnUrl);
  var  projectUrl=window.location.href.split("?")[1];
  console.log(projectUrl);
  //var cdnUrl =baseContent.cdnUrl;
  var wapLoginApp = new Vue({
      el: '#wapRegister',
      data: {
          mobileNumber:"",
          password:"",
          verification:"",
          isSendingSms:false,
          countDownNumber: 0,
          isSmsSent:false,
          sendSmsUrl:"/user/getVerificationCode",
          isRegisteringAccount:false,
          isdisabled:false
      },
  	  ready:function(){
  	    $("#wapRegister").show();
  	  },
      methods:{
          isMobileNumberValid: function () {
              //todo check this.mobileNumber is mobile
              var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
              if (!myreg.test(this.mobileNumber)) {
                  return false;
              } else {
                  return true;
              }
          },
          countDown: function () {
              setTimeout(function(){
                  if (this.countDownNumber >= 1) {
                      this.countDownNumber--;
                      this.countDown();
                  } else {
                      this.countDownNumber = 0;
                  }
              }.bind(this), 1000)
          },
          sendSms: function () {
              if (this.isSendingSms) {
                  return;
              }
              if (!this.isMobileNumberValid()) {
                  alert("填写正确的手机号");
                  return;
              }

              var data = {
                  telephone: this.mobileNumber
              };
              this.isSendingSms = true;
              pushData(this.sendSmsUrl,data,function(res) {
                  if(res.state){
                        this.countDownNumber = 120;           
                        this.countDown();
                        isSendingSms=false;
                        this.isSmsSent = true;
                  }else{
                    alert(res.message)
                  }
              }.bind(this))
          },
          registerAccount:function(){
              if(this.isRegisteringAccount){
                return;
              }
              if(!this.password||!this.mobileNumber||!this.verification){
                alert("手机号，密码，验证码为必填");
                return;
              }
              this.isRegisteringAccount=true;
              var url="/user/modifyPassword ";
              var data={password:this.password , telephone: this.mobileNumber,verification:this.verification};
              console.log(data)
              pushData(url,data,function(res){
                console.log(res);
                  this.isRegisteringAccount=false;
                  if(res.state){
                    alert("修改成功")
                    if(projectUrl){
                       var projectId=projectUrl.split("&")[0];
                       projectId=projectId.split("#")[1];
                       window.location.href ="/publicBundle/getProject.mobile.html#"+projectId ;
                    }else{
                      window.location.href = "/";
                    }                     
                  }else{
                    alert(res.message)
                  }
              }.bind(this))
          }
      }
  });
});
</script>
<script src="../js/js/rem_fix.js"></script>
<script src="../js/js/common.js"></script>
</body>
</html>